import React from 'react';
import dva from 'dva';
import { RouterContext } from 'dva/router';
import router from './router';
import { message } from 'antd';
import createLoading from 'dva-loading'

export default function createApp(opts, isServer) {

  var nowOption = ({
    ...createLoading({
      effects: true,
    }),
    history: opts.history,
    initialState: opts.initialState,
  });

  const app = dva(nowOption);

  app.model(require('./models/authorities/user'));
  app.model(require('./models/authorities/department'));
  app.model(require('./models/authorities/role'));
  app.model(require('./models/authorities/rolegroup'));
  app.model(require('./models/authorities/usermenu'));
  app.model(require('./models/authorities/useraction'));
  app.model(require('./models/authorities/power'));
  app.model(require('./models/account/index'));

  if (isServer) {
    app.router(({ history, renderProps }) => {
      return <RouterContext {...renderProps }
      />;
    });
  } else {
    app.router(router);
  }
  return app;
}